#!/usr/bin/python
# -*- coding: utf-8 -*-

import os
import sys
import re


project_path = os.path.abspath('.')

if not len(sys.argv) > 1:
	print u"脚本参数必须大于1...\n"

data_arr = list()
header_arr = ['wavelength']
for i, fn in enumerate(sys.argv[1:]):
	header_arr.append(os.path.basename(fn))
	with open(fn) as fid:
		j = 0
		for j, line in enumerate(fid):
			if j < 3:
				continue
			f_line = line.rstrip("\n").rstrip("\r")
			f_list = f_line.split(',')
			if i == 0:
				data_arr.append(f_list)
			else:
				data_arr[j-3].append(f_list[1])
data_arr.insert(0, header_arr)

save_path = os.path.join(project_path, 'cb.csv')
with open(save_path, 'w') as fid:
	for d_r in data_arr:
		fid.write("%s\n" % ','.join(d_r))
raw_input('press any to exit...')